from django.db import models
import datetime

# 动画
class NoinfoAnime(models.Model):
    name = models.CharField( max_length=255, blank=True, null=True)
    theme = models.CharField(max_length=100, blank=True, null=True)
    title = models.CharField(max_length=100, blank=True, null=True)
    season = models.CharField(max_length=100, blank=True, null=True)
    subtitle = models.CharField(max_length=100, blank=True, null=True)
    playmode = models.CharField(max_length=100, blank=True, null=True)
    dim = models.CharField(max_length=100, blank=True, null=True)
    episodes = models.IntegerField(blank=True, null=True)
    duration = models.IntegerField(blank=True, null=True)
    episode_start = models.IntegerField(blank=True, null=True)
    episode_end = models.IntegerField(blank=True, null=True)
    date_start = models.DateField(blank=True, null=True)
    date_end = models.DateField(blank=True, null=True)
    producer = models.CharField(max_length=100, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    update_time = models.DateTimeField(blank=True, null=True)

    def save(self, *args, **kwargs):
        if self.season is None or self.season=="":
            if self.subtitle is None or self.subtitle=="":
               self.name = str(self.title)
            else:
               self.name = str(self.title) + ':' + str(self.subtitle)
        else:
            if self.subtitle is None or self.subtitle=="":
               self.name = str(self.title) + str(self.season)
            else:
               self.name = str(self.title) + str(self.season) + ':' + str(self.subtitle)
        super().save(*args, **kwargs) 

    class Meta:
        managed = True
        db_table = 'noinfo_anime'

# 电影
class NoinfoMovie(models.Model):
    name = models.CharField( max_length=255, blank=True, null=True)
    theme = models.CharField(max_length=100, blank=True, null=True)
    title = models.CharField( max_length=255, blank=True, null=True)
    sort = models.CharField(max_length=100, blank=True, null=True)
    subtitle = models.CharField(max_length=100, blank=True, null=True)
    playmode = models.CharField(max_length=100, blank=True, null=True)
    dim = models.CharField(max_length=100, blank=True, null=True)
    duration = models.IntegerField(blank=True, null=True)
    date_start = models.DateField(blank=True, null=True)
    producer = models.CharField(max_length=100, blank=True, null=True)
    director = models.CharField(max_length=100, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    update_time = models.DateTimeField(blank=True, null=True)

    def save(self, *args, **kwargs):
        if self.sort is None or self.sort=="":
            if self.subtitle is None or self.subtitle=="":
               self.name = str(self.title)
            else:
               self.name = str(self.title) + ':' + str(self.subtitle)
        else:
            if self.subtitle is None or self.subtitle=="":
               self.name = str(self.title) + str(self.sort)
            else:
               self.name = str(self.title) + str(self.sort) + ':' + str(self.subtitle)
        super().save(*args, **kwargs) 

    class Meta:
        managed = True
        db_table = 'noinfo_movie'

# 电视剧
class NoinfoTeleplay(models.Model):
    name = models.CharField( max_length=255, blank=True, null=True)
    theme = models.CharField(max_length=100, blank=True, null=True)
    title = models.CharField(max_length=100, blank=True, null=True)
    season = models.CharField(max_length=100, blank=True, null=True)
    subtitle = models.CharField(max_length=100, blank=True, null=True)
    episodes = models.IntegerField(blank=True, null=True)
    duration = models.IntegerField(blank=True, null=True)
    episode_start = models.IntegerField(blank=True, null=True)
    episode_end = models.IntegerField(blank=True, null=True)
    date_start = models.DateField(blank=True, null=True)
    date_end = models.DateField(blank=True, null=True)
    producer = models.CharField(max_length=100, blank=True, null=True)
    director = models.CharField(max_length=100, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    update_time = models.DateTimeField(blank=True, null=True)

    def save(self, *args, **kwargs):
        if self.season is None or self.season=="":
            if self.subtitle is None or self.subtitle=="":
               self.name = str(self.title)
            else:
               self.name = str(self.title) + ':' + str(self.subtitle)
        else:
            if self.subtitle is None or self.subtitle=="":
               self.name = str(self.title) + str(self.season)
            else:
               self.name = str(self.title) + str(self.season) + ':' + str(self.subtitle)
        super().save(*args, **kwargs) 

    class Meta:
        managed = True
        db_table = 'noinfo_teleplay'

# 小说
class NoinfoNovel(models.Model):
    name = models.CharField( max_length=255, blank=True, null=True)
    theme = models.CharField(max_length=100, blank=True, null=True)
    title = models.CharField(max_length=100, blank=True, null=True)
    sort = models.CharField(max_length=100, blank=True, null=True)
    subtitle = models.CharField(max_length=100, blank=True, null=True)
    words = models.IntegerField(blank=True, null=True)
    chapters = models.IntegerField(blank=True, null=True)
    date_start = models.DateField(blank=True, null=True)
    date_end = models.DateField(blank=True, null=True)
    author = models.CharField(max_length=100, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    update_time = models.DateTimeField(blank=True, null=True)

    def save(self, *args, **kwargs):
        if self.sort is None or self.sort=="":
            if self.subtitle is None or self.subtitle=="":
               self.name = str(self.title)
            else:
               self.name = str(self.title) + ':' + str(self.subtitle)
        else:
            if self.subtitle is None or self.subtitle=="":
               self.name = str(self.title) + str(self.sort)
            else:
               self.name = str(self.title) + str(self.sort) + ':' + str(self.subtitle)
        super().save(*args, **kwargs) 

    class Meta:
        managed = True
        db_table = 'noinfo_novel'

# 作品系列
class NoinfoTheme(models.Model):
    theme = models.CharField(max_length=100, blank=True, null=True)
    status_view = models.CharField(max_length=100, blank=True, null=True)
    author = models.CharField(max_length=100, blank=True, null=True)
    universe = models.CharField(max_length=100, blank=True, null=True)
    source_type = models.CharField(max_length=100, blank=True, null=True)
    source_name = models.CharField(max_length=100, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    update_time = models.DateTimeField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'noinfo_theme'

# 观看记录
class NoinfoWatchrecord(models.Model):
    name = models.CharField(max_length=100, blank=True, null=True)
    code = models.CharField(max_length=100, blank=True, null=True)
    times = models.IntegerField(blank=True, null=True)
    date_watch_start = models.DateField(blank=True, null=True)
    date_watch_end = models.DateField(blank=True, null=True)
    status = models.CharField(max_length=100, blank=True, null=True)
    type = models.CharField(max_length=100, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    update_time = models.DateTimeField(blank=True, null=True)
    
    class Meta:
        managed = True
        db_table = 'noinfo_watchrecord'

# 追番状态
class NoinfoUpdating(models.Model):
    title = models.CharField(max_length=100, blank=True, null=True)
    week = models.CharField(max_length=100, blank=True, null=True)
    status = models.CharField(max_length=100, blank=True,null=True)
    create_time = models.DateTimeField(blank=True, null=True)
    update_time = models.DateTimeField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'noinfo_updating'
